<template>
  <div class="ChildPage TablePage" v-loading="loading">
    <vb-page ref="page">
      <template #table-docType="scope">
        <span v-if="scope.row.docType === 'SA'">销售单</span><span v-else class="refund">退款单</span>
      </template>
      <template #table-qty="scope">
        <span :class="scope.row.docType === 'SA'? '': 'refund'">{{ scope.row.docType === 'SA'? '': '-' }}{{ scope.row.qty }}</span>
      </template>
      <template #table-amount="scope">
        <span :class="scope.row.docType === 'SA'? '': 'refund'">{{ scope.row.docType === 'SA'? '': '-' }}{{ Number(scope.row.amount || 0).toFixed(2) }}</span>
      </template>
      <template #table-error="scope">
        <el-tag size="small" :type="scope.row.error? 'danger': 'success'">{{ scope.row.error? '失败': '成功' }}</el-tag>
      </template>
      <template #table-handle-param="scope">
        <el-button type="text" size="mini" @click="$refs.contentDialog.doShow('调用参数', scope.row.param)">调用参数</el-button>
      </template>
      <template #table-handle-content="scope">
        <el-button type="text" size="mini" @click="$refs.contentDialog.doShow('对接报文', scope.row.soap)">对接报文</el-button>
      </template>
      <template #table-handle-retry="scope">
        <el-button v-if="scope.row.error" type="text" size="mini" @click="retry(scope.row.id)">重推</el-button>
        <span v-else></span>
      </template>
    </vb-page>
  </div>
  <contentDialog ref="contentDialog"></contentDialog>
</template>

<script>
import contentDialog from "./history/components/contentDialog.vue";
import {getCurrentInstance, ref} from "vue";
export default {
  mixins: [],
  components: {
    contentDialog
  },
  data() {
    return {
    }
  },
  setup() {
    const { proxy } = getCurrentInstance()
    const loading = ref(false)

    // 打开对话框
    const retry = async(id) => {
      loading.value = true
      try {
        let res = await proxy.callApi('ws_history_retry', { id })
        proxy.$message.success('已经重推!')
      } finally {
        proxy.$refs.page.data.reload()
        loading.value = false
      }
    }
    return {
      loading,
      retry
    }
  }
}
</script>

<style lang="scss" scoped>
.refund {
  color: #f56c6c;
}
</style>
